{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6431f4f5",
   "metadata": {},
   "source": [
    "### 填空题1"
   ]
  },
  {
   "cell_type": "raw",
   "id": "5da12bea",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　一个包含有2019个结点的无向连通图，最少包含多少条边？\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "344f7b87",
   "metadata": {},
   "source": [
    "### 填空题2"
   ]
  },
  {
   "cell_type": "raw",
   "id": "02893fc5",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　将LANQIAO中的字母重新排列，可以得到不同的单词，如LANQIAO、AAILNOQ等，注意这7个字母都要被用上，单词不一定有具体的英文意义。\n",
    "　　请问，总共能排列如多少个不同的单词。\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2755e3ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2520\n"
     ]
    }
   ],
   "source": [
    "from itertools import permutations\n",
    "\n",
    "print(len(set(list(permutations(list('LANQIAO'), 7)))))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e05d5f46",
   "metadata": {},
   "source": [
    "### 填空题3"
   ]
  },
  {
   "cell_type": "raw",
   "id": "c7b5bbbd",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　在计算机存储中，12.5MB是多少字节？\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c5a504c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "kb = 1024\n",
    "mb = 1024 * kb\n",
    "print(12.5 * mb)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f964151a",
   "metadata": {},
   "source": [
    "### 填空题4"
   ]
  },
  {
   "cell_type": "raw",
   "id": "4522640e",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　由1对括号，可以组成一种合法括号序列：()。\n",
    "　　由2对括号，可以组成两种合法括号序列：()()、(())。\n",
    "　　由4对括号组成的合法括号序列一共有多少种？\n",
    "答案提交\n",
    "　　这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "096644fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "import itertools\n",
    "data = ['(',')','(',')','(',')','(',')','(',')','(',')','(',')','(',')'] \n",
    "product_res = itertools.product(data, data)\n",
    "\n",
    "num = 0\n",
    "for part in list(product_res):\n",
    "    if part == part[::-1]:\n",
    "        num += 1\n",
    "\n",
    "print(num)    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3fae653b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "chars = list()\n",
    "\n",
    "chars.extend(['(' for _ in range(4)])\n",
    "\n",
    "chars.extend([')' for _ in range(4)])\n",
    "\n",
    "from itertools import product\n",
    "\n",
    "results = list(product(chars, repeat=8))\n",
    "\n",
    "\n",
    "num = 0\n",
    "for result in results:\n",
    "    if result == result[::-1]:\n",
    "        num = num + 1 \n",
    "\n",
    "print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d12b67eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "num = 0 \n",
    "for i in range(10000000, 1000000000):\n",
    "    string = str(i)\n",
    "    \n",
    "    if string.count('1') == 4 and string.count('2') == 4:\n",
    "        if string == string[::-1]:\n",
    "            num = num + 1\n",
    "            \n",
    "print(num)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d520c7c4",
   "metadata": {},
   "source": [
    "### 编程题1 凯撒密码加密"
   ]
  },
  {
   "cell_type": "raw",
   "id": "cb067db9",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　给定一个单词，请使用凯撒密码将这个单词加密。\n",
    "　　凯撒密码是一种替换加密的技术，单词中的所有字母都在字母表上向后偏移3位后被替换成密文。即a变为d，b变为e，…，w变为z，x变为a，y变为b，z变为c。\n",
    "　　例如，lanqiao会变成odqtldr。\n",
    "输入格式\n",
    "　　输入一行，包含一个单词，单词中只包含小写英文字母。\n",
    "输出格式\n",
    "　　输出一行，表示加密后的密文。\n",
    "样例输入\n",
    "lanqiao\n",
    "样例输出\n",
    "odqtldr\n",
    "评测用例规模与约定\n",
    "　　对于所有评测用例，单词中的字母个数不超过100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b25cd06",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "string = list(input())\n",
    "\n",
    "for i in range(len(string)):\n",
    "    \n",
    "    char_ord = ord(string[i]) + 3\n",
    "        \n",
    "    string[i] = chr(char_ord if char_ord <= 122 else char_ord - 26)\n",
    "\n",
    "print(\"\".join(string))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8241d03",
   "metadata": {},
   "source": [
    "### 编程题2 反倍数"
   ]
  },
  {
   "cell_type": "raw",
   "id": "8a81c20d",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　给定三个整数 a, b, c，如果一个整数既不是 a 的整数倍也不是 b 的整数倍还不是 c 的整数倍，则这个数称为反倍数。\n",
    "　　请问在 1 至 n 中有多少个反倍数。\n",
    "输入格式\n",
    "　　输入的第一行包含一个整数 n。\n",
    "　　第二行包含三个整数 a, b, c，相邻两个数之间用一个空格分隔。\n",
    "输出格式\n",
    "　　输出一行包含一个整数，表示答案。\n",
    "样例输入\n",
    "30\n",
    "2 3 6\n",
    "样例输出\n",
    "10\n",
    "样例说明\n",
    "　　以下这些数满足要求：1, 5, 7, 11, 13, 17, 19, 23, 25, 29。\n",
    "评测用例规模与约定\n",
    "　　对于 40% 的评测用例，1 <= n <= 10000。\n",
    "　　对于 80% 的评测用例，1 <= n <= 100000。\n",
    "　　对于所有评测用例，1 <= n <= 1000000，1 <= a <= n，1 <= b <= n，1 <= c <= n。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e915b12",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "\n",
    "a, b, c = map(int, input().split())\n",
    "\n",
    "nums = list()\n",
    "\n",
    "for i in range(1, n+1):\n",
    "    \n",
    "    if i % a != 0 and i % b != 0 and i % c != 0:\n",
    "        nums.append(i)\n",
    "        \n",
    "print(len(nums))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c665627",
   "metadata": {},
   "source": [
    "### 编程题3 摆动序列"
   ]
  },
  {
   "cell_type": "raw",
   "id": "bd9b8435",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　如果一个序列的奇数项都比前一项大，偶数项都比前一项小，则称为一个摆动序列。即 a[2i]<a[2i-1], a[2i+1]>a[2i]。\n",
    "　　小明想知道，长度为 m，每个数都是 1 到 n 之间的正整数的摆动序列一共有多少个。\n",
    "输入格式\n",
    "　　输入一行包含两个整数 m，n。\n",
    "输出格式\n",
    "　　输出一个整数，表示答案。答案可能很大，请输出答案除以10000的余数。\n",
    "样例输入\n",
    "3 4\n",
    "样例输出\n",
    "14\n",
    "样例说明\n",
    "　　以下是符合要求的摆动序列：\n",
    "　　2 1 2\n",
    "　　2 1 3\n",
    "　　2 1 4\n",
    "　　3 1 2\n",
    "　　3 1 3\n",
    "　　3 1 4\n",
    "　　3 2 3\n",
    "　　3 2 4\n",
    "　　4 1 2\n",
    "　　4 1 3\n",
    "　　4 1 4\n",
    "　　4 2 3\n",
    "　　4 2 4\n",
    "　　4 3 4\n",
    "评测用例规模与约定\n",
    "　　对于 20% 的评测用例，1 <= n, m <= 5；\n",
    "　　对于 50% 的评测用例，1 <= n, m <= 10；\n",
    "　　对于 80% 的评测用例，1 <= n, m <= 100；\n",
    "　　对于所有评测用例，1 <= n, m <= 1000。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1eb06567",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "m, n = map(int, input().split())\n",
    "\n",
    "num = [i for i in range(1, n+1)]\n",
    "\n",
    "from itertools import product\n",
    "\n",
    "nums = list(product(num, repeat=3))\n",
    "\n",
    "\n",
    "def judge(value):\n",
    "    \n",
    "    for i in range(2, len(value), 2):\n",
    "        \n",
    "        if value[i] <= value[i-1]:\n",
    "            \n",
    "            return False\n",
    "        \n",
    "        \n",
    "    for i in range(1, len(value), 2):\n",
    "        \n",
    "        if value[i] >= value[i-1]:\n",
    "            \n",
    "            return False\n",
    "        \n",
    "    return True\n",
    "    \n",
    "for value in nums:\n",
    "    \n",
    "    if judge(value):\n",
    "        \n",
    "        print(value)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "332f2a5c",
   "metadata": {},
   "source": [
    "### 编程题4 螺旋矩阵"
   ]
  },
  {
   "cell_type": "raw",
   "id": "223ddda5",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　对于一个 n 行 m 列的表格，我们可以使用螺旋的方式给表格依次填上正整数，我们称填好的表格为一个螺旋矩阵。\n",
    "　　例如，一个 4 行 5 列的螺旋矩阵如下：\n",
    "　　1  2  3  4  5\n",
    "　　14 15 16 17 6\n",
    "　　13 20 19 18 7\n",
    "　　12 11 10 9  8\n",
    "输入格式\n",
    "　　输入的第一行包含两个整数 n, m，分别表示螺旋矩阵的行数和列数。\n",
    "　　第二行包含两个整数 r, c，表示要求的行号和列号。\n",
    "输出格式\n",
    "　　输出一个整数，表示螺旋矩阵中第 r 行第 c 列的元素的值。\n",
    "样例输入\n",
    "4 5\n",
    "2 2\n",
    "样例输出\n",
    "15\n",
    "评测用例规模与约定\n",
    "　　对于 30% 的评测用例，2 <= n, m <= 20。\n",
    "　　对于 70% 的评测用例，2 <= n, m <= 100。\n",
    "　　对于所有评测用例，2 <= n, m <= 1000，1 <= r <= n，1 <= c <= m。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "841668dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "n, m = map(int, input().split())\n",
    "\n",
    "r, c = map(int, input().split())\n",
    "\n",
    "nums = [[0 for _ in range(m)] for _ in range(n)]\n",
    "_nums = [[0 for _ in range(m)] for _ in range(n)]\n",
    "\n",
    "x, y = 0, 0\n",
    "\n",
    "i = 1\n",
    "while i < n * m:\n",
    "    while y < m and _nums[x][y] == 0:\n",
    "        nums[x][y] = i\n",
    "        _nums[x][y] = 1\n",
    "        i = i + 1\n",
    "        y = y + 1\n",
    "        \n",
    "    y -= 1\n",
    "    x += 1\n",
    "    \n",
    "    while x < n and _nums[x][y] == 0:\n",
    "        nums[x][y] = i\n",
    "        _nums[x][y] = 1\n",
    "        i = i + 1\n",
    "        x = x + 1\n",
    "        \n",
    "    x -= 1\n",
    "    y -= 1\n",
    "    \n",
    "    while y >= 0 and _nums[x][y] == 0:\n",
    "        nums[x][y] = i\n",
    "        _nums[x][y] = 1\n",
    "        i = i + 1\n",
    "        y = y - 1\n",
    "        \n",
    "    x -= 1\n",
    "    y += 1\n",
    "    \n",
    "    while x >= 0 and _nums[x][y] == 0:\n",
    "        nums[x][y] = i\n",
    "        _nums[x][y] = 1\n",
    "        i = i + 1\n",
    "        x = x - 1\n",
    "        \n",
    "    x += 1\n",
    "    y += 1\n",
    "    \n",
    "\n",
    "print(nums)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0b91d41",
   "metadata": {},
   "source": [
    "### 编程题5 村庄通电"
   ]
  },
  {
   "cell_type": "raw",
   "id": "4c28c7c5",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　2015年，全中国实现了户户通电。作为一名电力建设者，小明正在帮助一带一路上的国家通电。\n",
    "　　这一次，小明要帮助 n 个村庄通电，其中 1 号村庄正好可以建立一个发电站，所发的电足够所有村庄使用。\n",
    "　　现在，这 n 个村庄之间都没有电线相连，小明主要要做的是架设电线连接这些村庄，使得所有村庄都直接或间接的与发电站相通。\n",
    "　　小明测量了所有村庄的位置（坐标）和高度，如果要连接两个村庄，小明需要花费两个村庄之间的坐标距离加上高度差的平方，形式化描述为坐标为 (x_1, y_1) 高度为 h_1 的村庄与坐标为 (x_2, y_2) 高度为 h_2 的村庄之间连接的费用为\n",
    "　　sqrt((x_1-x_2)(x_1-x_2)+(y_1-y_2)(y_1-y_2))+(h_1-h_2)*(h_1-h_2)。\n",
    "　　在上式中 sqrt 表示取括号内的平方根。请注意括号的位置，高度的计算方式与横纵坐标的计算方式不同。\n",
    "　　由于经费有限，请帮助小明计算他至少要花费多少费用才能使这 n 个村庄都通电。\n",
    "输入格式\n",
    "　　输入的第一行包含一个整数 n ，表示村庄的数量。\n",
    "　　接下来 n 行，每个三个整数 x, y, h，分别表示一个村庄的横、纵坐标和高度，其中第一个村庄可以建立发电站。\n",
    "输出格式\n",
    "　　输出一行，包含一个实数，四舍五入保留 2 位小数，表示答案。\n",
    "样例输入\n",
    "4\n",
    "1 1 3\n",
    "9 9 7\n",
    "8 8 6\n",
    "4 5 4\n",
    "样例输出\n",
    "17.41\n",
    "评测用例规模与约定\n",
    "　　对于 30% 的评测用例，1 <= n <= 10；\n",
    "　　对于 60% 的评测用例，1 <= n <= 100；\n",
    "　　对于所有评测用例，1 <= n <= 1000，0 <= x, y, h <= 10000。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e6a2d99",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from math import sqrt\n",
    "n = int(input())\n",
    "\n",
    "countrys = [list(map(int, input().split())) for _ in range(n)]\n",
    "\n",
    "center = countrys.pop(0)\n",
    "\n",
    "def calculate(center, countrys):\n",
    "    \n",
    "    des = [pow(country[0]-center[0], 2)+\n",
    "           pow(country[1]-center[1], 2)+\n",
    "           pow(country[2]-center[2], 2) for country in countrys]\n",
    "    \n",
    "    country_index = des.index(min(des))\n",
    "    \n",
    "    return country_index\n",
    "\n",
    "result = 0\n",
    "\n",
    "while len(countrys) != 0:\n",
    "    \n",
    "    country_index = calculate(center, countrys)\n",
    "    \n",
    "    result = result + sqrt(pow(center[0] - countrys[country_index][0], 2)+ \n",
    "                           pow(center[1] - countrys[country_index][1], 2)+\n",
    "                           pow(center[2] - countrys[country_index][2], 2))\n",
    "                            \n",
    "    center = countrys.pop(country_index)\n",
    "\n",
    "\n",
    "print(round(result, 2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e948e729",
   "metadata": {},
   "source": [
    "### 编程题6 小明植树"
   ]
  },
  {
   "cell_type": "raw",
   "id": "e64cc5e1",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　小明和朋友们一起去郊外植树，他们带了一些在自己实验室精心研究出的小树苗。\n",
    "　　小明和朋友们一共有 n 个人，他们经过精心挑选，在一块空地上每个人挑选了一个适合植树的位置，总共 n 个。他们准备把自己带的树苗都植下去。\n",
    "　　然而，他们遇到了一个困难：有的树苗比较大，而有的位置挨太近，导致两棵树植下去后会撞在一起。\n",
    "　　他们将树看成一个圆，圆心在他们找的位置上。如果两棵树对应的圆相交，这两棵树就不适合同时植下（相切不受影响），称为两棵树冲突。\n",
    "　　小明和朋友们决定先合计合计，只将其中的一部分树植下去，保证没有互相冲突的树。他们同时希望这些树所能覆盖的面积和（圆面积和）最大。\n",
    "输入格式\n",
    "　　输入的第一行包含一个整数 n ，表示人数，即准备植树的位置数。\n",
    "　　接下来 n 行，每行三个整数 x, y, r，表示一棵树在空地上的横、纵坐标和半径。\n",
    "输出格式\n",
    "　　输出一行包含一个整数，表示在不冲突下可以植树的面积和。由于每棵树的面积都是圆周率的整数倍，请输出答案除以圆周率后的值（应当是一个整数）。\n",
    "样例输入\n",
    "6\n",
    "1 1 2\n",
    "1 4 2\n",
    "1 7 2\n",
    "4 1 2\n",
    "4 4 2\n",
    "4 7 2\n",
    "样例输出\n",
    "12\n",
    "评测用例规模与约定\n",
    "　　对于 30% 的评测用例，1 <= n <= 10；\n",
    "　　对于 60% 的评测用例，1 <= n <= 20；\n",
    "　　对于所有评测用例，1 <= n <= 30，0 <= x, y <= 1000，1 <= r <= 1000。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8366e1d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def isTure(i):\n",
    "    for j in range(n):\n",
    "        if i != j and vis[j]:\n",
    "            if (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) < (r[i] + r[j]) * (r[i] + r[j]):\n",
    "                return False\n",
    "    return True\n",
    "\n",
    "\n",
    "def dfs(step, sum):\n",
    "    global ans\n",
    "    if step == n:\n",
    "        ans = max(ans, sum)\n",
    "        return\n",
    "    for i in range(n):\n",
    "        if vis[i] == 0:\n",
    "            tmp = r[i]\n",
    "            if isTure(i) == False:\n",
    "                r[i] = 0\n",
    "            vis[i] = 1\n",
    "            dfs(step + 1, sum + r[i] * r[i])\n",
    "            vis[i] = 0\n",
    "            r[i] = tmp\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    PI = 3.14\n",
    "    ans = 0\n",
    "    x = []\n",
    "    y = []\n",
    "    r = []\n",
    "    n = int(input())\n",
    "    vis = [0 for _ in range(n)]\n",
    "    for _ in range(n):\n",
    "        xt, yt, rt = map(int, input().split())\n",
    "        x.append(xt)\n",
    "        y.append(yt)\n",
    "        r.append(rt)\n",
    "    dfs(0, 0)\n",
    "\n",
    "    print(ans)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "lanqiaobei",
   "language": "python",
   "name": "lanqiaobei"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
